package ee.ttu.lecturerate.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class TimeTable implements Serializable
{	
	private static final long serialVersionUID = 1L;
	
	private List<Lecture> upcoming;
	private List<Lecture> ongoing;
	private List<Lecture> bygone;
	
	public TimeTable()
	{
		upcoming = new ArrayList<Lecture>();
		ongoing = new ArrayList<Lecture>();
		bygone = new ArrayList<Lecture>();
	}
	
	public void addUpcomingLecture(Lecture lecture)
	{
		upcoming.add(lecture);
	}
	
	public void addOngoingLecture(Lecture lecture)
	{
		ongoing.add(lecture);
	}
	
	public void addBygoneLecture(Lecture lecture)
	{
		bygone.add(lecture);
	}
	
	public List<Lecture> getUpcomingLectures()
	{
		Collections.sort(upcoming, new DateComparator());
		return upcoming;
	}
	
	public List<Lecture> getOngoingLectures()
	{
		Collections.sort(ongoing, new DateComparator());
		return ongoing;
	}
	
	public List<Lecture> getBygoneLectures()
	{
		Collections.sort(bygone, new DateComparator());
		return bygone;
	}
	
	class DateComparator implements Comparator<Lecture>
	{
		@Override
		public int compare(Lecture lecture1, Lecture lecture2)
		{
			return lecture1.getDate().compareTo(lecture2.getDate());
		}
		
	}
}
